clear all 
set more off


cd "/Users/wagnerza/Dropbox/ors_quality_R01/"
use "data/Household/HH_dce.dta", clear


areg chosen i.medicine i.price i.time i.treat i.quality ib2.name , cluster(hhid) abs(set)

*areg chosen i.medicine i.price i.time i.treat i.quality i.name if medicine!=6, cluster(hhid) abs(set)


	gen effect=0 if _n==29
	replace effect=_b[2.medicine] if _n==28
	replace effect=_b[3.medicine] if _n==27
	replace effect=_b[4.medicine] if _n==26
	replace effect=_b[5.medicine] if _n==25
	
	replace effect=0 if _n==22
	replace effect=_b[2.price] if _n==21
	replace effect=_b[3.price] if _n==20
	
	replace effect=0 if _n==17
	replace effect=_b[2.time] if _n==16
	replace effect=_b[3.time] if _n==15
	
	replace effect=0 if _n==12
	replace effect=_b[2.treat] if _n==11
	
	replace effect=0 if _n==8
	replace effect=_b[2.quality] if _n==7
	replace effect=_b[3.quality] if _n==6

	replace effect=0 if _n==3
	replace effect=_b[1.name] if _n==2
	replace effect=_b[3.name] if _n==1
	

*Upper

	gen ub=0 if _n==29
	replace ub=_b[2.medicine]+1.96*_se[2.medicine] if _n==28
	replace ub=_b[3.medicine]+1.96*_se[3.medicine] if _n==27
	replace ub=_b[4.medicine]+1.96*_se[4.medicine] if _n==26
	replace ub=_b[5.medicine]+1.96*_se[5.medicine] if _n==25
	
	replace ub=0 if _n==22
	replace ub=_b[2.price]+1.96*_se[2.price] if _n==21
	replace ub=_b[3.price]+1.96*_se[3.price] if _n==20
	
	replace ub=0 if _n==17
	replace ub=_b[2.time]+1.96*_se[2.time] if _n==16
	replace ub=_b[3.time]+1.96*_se[3.time] if _n==15
	
	replace ub=0 if _n==12
	replace ub=_b[2.treat]+1.96*_se[2.treat] if _n==11
	
	replace ub=0 if _n==8
	replace ub=_b[2.quality]+1.96*_se[2.quality] if _n==7
	replace ub=_b[3.quality]+1.96*_se[3.quality] if _n==6

	replace ub=0 if _n==3
	replace ub=_b[1.name]+1.96*_se[1.name] if _n==2
	replace ub=_b[3.name]+1.96*_se[3.name] if _n==1

*Lower

	
	gen lb=0 if _n==29
	replace lb=_b[2.medicine]-1.96*_se[2.medicine] if _n==28
	replace lb=_b[3.medicine]-1.96*_se[3.medicine] if _n==27
	replace lb=_b[4.medicine]-1.96*_se[4.medicine] if _n==26
	replace lb=_b[5.medicine]-1.96*_se[5.medicine] if _n==25
	
	replace lb=0 if _n==22
	replace lb=_b[2.price]-1.96*_se[2.price] if _n==21
	replace lb=_b[3.price]-1.96*_se[3.price] if _n==20
	
	replace lb=0 if _n==17
	replace lb=_b[2.time]-1.96*_se[2.time] if _n==16
	replace lb=_b[3.time]-1.96*_se[3.time] if _n==15
	
	replace lb=0 if _n==12
	replace lb=_b[2.treat]-1.96*_se[2.treat] if _n==11
	
	replace lb=0 if _n==8
	replace lb=_b[2.quality]-1.96*_se[2.quality] if _n==7
	replace lb=_b[3.quality]-1.96*_se[3.quality] if _n==6

	replace lb=0 if _n==3
	replace lb=_b[1.name]-1.96*_se[1.name] if _n==2
	replace lb=_b[3.name]-1.96*_se[3.name] if _n==1
	
	
	gen axis=_n if _n<30
	
	#delimit;
	label define attributes 
	30 "{bf:MEDICINES PRESCRIBED}"
	29 "ORS only"
	28 "ORS+Zinc"
	27 "ORS+Zinc+Abx"
	26 "Abx Only"
	25 "Injection"
	24 " "
	23 "{bf:DOCTOR FEE}"
	22 "100 INR"
	21 "300 INR"
	20 "500 INR"
	19 " "
	18 "{bf:TIME TO CLINIC}"
	17 "10 Minutes"
	16 "30 Minutes"
	15 "60 Minutes"
	14 " "
	13 "{bf:KINDESS TO PATIENT}"
	12 "Provider is rude"
	11 "Provider is kind"
	10 " "
	9 "{bf:QUALITY RATING}"
	8 "1 star"
	7 "3 star"
	6 "5 star"
	5 " "
	4 "{bf:NAME}"
	3 "Hindu Name"
	2 "Dalit Name"
	1 "Muslim Name";
	#delimit cr

	label values axis attributes

	
	twoway (scatter axis effect, color(midblue) )(rcap ub lb axis, horizontal color(midblue)), ///
	ylabel(1(1)30, valuelabel angle(0) notick) ///
	xlabel(,grid gstyle(dot)) ///
	ytitle(" ") ///
	xline(0, lpattern(dash)) ///
	xtitle("Change in Pr(Choice)") ///
	ysize(6) xsize(5) ///
	scheme(s1color) ///
	xlabel(-.5(.1).5) ///
	legend(order(1 "Estimate" 2 "95% CI"))
	
	graph export "figures/dce_results.pdf", replace
	
	twoway (scatter axis effect if axis>=25, color(midblue) )(rcap ub lb axis if axis>=25, horizontal color(midblue)), ///
	ylabel(24 25(1)30, valuelabel angle(0) notick) ///
	xlabel(,grid gstyle(dot)) ///
	ytitle(" ") ///
	xline(0, lpattern(dash)) ///
	xtitle("Change in Pr(Choice)") ///
	ysize(6) xsize(5) ///
	scheme(s1color) ///
	xlabel(-.2(.05).2) ///
	legend(order(1 "Estimate" 2 "95% CI"))

